package openase.audiosearch.comm.response.encoder;

import java.nio.ByteBuffer;

import openase.audiosearch.comm.StringFormatUtils;
import openase.audiosearch.comm.response.ResponseType;
import openase.audiosearch.comm.response.SearchResult;


public class SearchResultResponseEncoder implements ResponseEncoder<SearchResult> {

	public ByteBuffer encode(SearchResult response) {
		byte[] result = StringFormatUtils.getUtf8(response.getResult());

		ByteBuffer buffer = ByteBuffer.allocate(1 + 4 + result.length);
		buffer.put(ResponseType.SEARCH_RESULT.getId());
		buffer.putInt(result.length);
		buffer.put(result);

		return buffer;

	}
}
